| 123456789101112131415161718192021222324252627282930313233 |
- import { NextApiRequest, NextApiResponse } from 'next'
- import { getPgMetaRedirectUrl } from './tables'
- import { fetchGet } from '@/data/fetchers'
- import { constructHeaders } from '@/lib/api/apiHelpers'
- import apiWrapper from '@/lib/api/apiWrapper'
- export default (req: NextApiRequest, res: NextApiResponse) =>
- apiWrapper(req, res, handler, { withAuth: true })
- async function handler(req: NextApiRequest, res: NextApiResponse) {
- const { method } = req
- switch (method) {
- case 'GET':
- return handleGetAll(req, res)
- default:
- res.setHeader('Allow', ['GET'])
- res.status(405).json({ error: { message: `Method ${method} Not Allowed` } })
- }
- }
- const handleGetAll = async (req: NextApiRequest, res: NextApiResponse) => {
- const headers = constructHeaders(req.headers)
- const response = await fetchGet(getPgMetaRedirectUrl(req, 'materialized-views'), { headers })
- if (response.error) {
- const { code, message } = response.error
- return res.status(code).json({ message })
- } else {
- return res.status(200).json(response)
- }
- }
|